<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cart_model extends CI_Model {
	
	function add_cart() {
		
	}
	
	function select_all() {
		
		$this->db->select('*');
		$this->db->from('cart');
		$this->db->join('inventories','cart.mdc_id = inventories.mdc_id','left');
		$this->db->join('prices','cart.price_id = prices.price_id','left');
		$this->db->join('mdctype','cart.mdctype_id = mdctype.mdctype_id','left');
		$this->db->join('users','cart.user_id = users.user_id','left');
		$query = $this -> db -> get();
		return $query->result_array();
	}
	
	function _getAll() {
		
		$result = $this->db->get('cart')->result();
		return $result;
	}
	
	function _getDetail($mdc_name,$price_type,$mdc_type,$name){
	
		$result = $this->db->where('mdc_name', $mdc_name)->get('inventories')->row();
		$result = $this->db->where('price_typr', $price_type)->get('prices')->row();
		$result = $this->db->where('mdc_type', $mdc_type)->get('mdctype')->row();
		$result = $this->db->where('name', $name)->get('users')->row();
		return $result;
	}
	
	function insert($data) {
	
		$this->db->insert('cart',$data);
		$insert_id = $this->db->insert_id();
		return $insert_id;
	}
	
	function select_order($id) {
	
		$this->db->select('*');
		$this->db->from('cart');
		$this->db->where('cart.cart_id',$id);
		$qurey = $this->db->get();
		return $qurey->row_array();
	}	
	
	function select_amount($id) {
	
		$this->db->select('mdc_amount');
		$this->db->from('cart');
		$this->db->where('cart.cart_id',$id);
		$qurey = $this->db->get();
		return $qurey->row_array();
	}
	
	function update_amount($id,$total) {
	
		$this->db->where('cart_id',$id);
		$this->db->update('cart',$total);
	}
	
	function update_status($id,$data) {
	
		$this->db->where('cart_id',$id);
		$this->db->update('cart',$data);
	}
	function select_order_user($user_id) {
	
		$this->db->select('*');
		$this->db->from('cart');
		$this->db->where('cart.cart_id',$user_id);
		$this->db->join('inventories','cart.cart_id = inventories.cart_id','left');
		$qurey = $this->db->get();
		return $qurey->row_array();
	}
}